<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->
    
        <meta name="description" content="gulp这个工具依赖node环境 所以在使用gulp之前需要安装node环境好处：可以使浏览器能够自动刷新，将LESS转换成CSS，压缩文件等基本使用流程建一个gulpfile.js文件gulp +任务名字(不是文件名字) 执行  //如果不断刷新就重新执行一次  //html和css,js混在一起">
    

    <!--Author-->
    
        <meta name="author" content="John Doe">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="gulp基本使用流程"/>
    

    <!--Open Graph Description-->
    

    <!--Open Graph Site Name-->
    <meta property="og:site_name" content="Hexo"/>

    <!--Type page-->
    
        <meta property="og:type" content="article" />
    

    <!--Page Cover-->
    

        <meta name="twitter:card" content="summary" />
    

    <!-- Title -->
    
    <title>gulp基本使用流程 - Hexo</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet" />

    <!-- Google Analytics -->
    


    <!-- favicon -->
    
	
</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">逐风</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>gulp基本使用流程</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                        
                            2016-10-13
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>gulp这个工具依赖node环境 所以在使用gulp之前需要安装node环境<br>好处：可以使浏览器能够自动刷新，将LESS转换成CSS，压缩文件等<br>基本使用流程<br>建一个gulpfile.js文件<br>gulp +任务名字(不是文件名字) 执行  //如果不断刷新就重新执行一次  //html和css,js混在一起无法压缩成功<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div></pre></td><td class="code"><pre><div class="line">//gulp实现 压缩CSS,js,html,image,less转css,以服务器形式启动浏览器并自动刷新</div><div class="line">// 引入gulp</div><div class="line">var gulp = require(&apos;gulp&apos;);</div><div class="line">// 压缩css插件</div><div class="line">var cleanCSS = require(&apos;gulp-clean-css&apos;);</div><div class="line">// 文件合并</div><div class="line">var concat = require(&apos;gulp-concat&apos;);</div><div class="line">// js压缩插件</div><div class="line">var uglify = require(&apos;gulp-uglify&apos;);</div><div class="line">// 图片压缩插件</div><div class="line">var imagemin = require(&apos;gulp-imagemin&apos;);</div><div class="line">// html压缩插件</div><div class="line">var htmlmin = require(&apos;gulp-htmlmin&apos;);</div><div class="line">// less转CSS插件</div><div class="line">var less = require(&apos;gulp-less&apos;);</div><div class="line">// 引入提供静态资源服务的插件</div><div class="line">var browserSync = require(&apos;browser-sync&apos;).create();</div><div class="line">// 用来刷新浏览器的方法</div><div class="line">var reload      = browserSync.reload;</div><div class="line"></div><div class="line">gulp.task(&apos;default&apos;,[&apos;cssmin&apos;,&apos;jsmin&apos;,&apos;imagemin&apos;,&apos;htmlmin&apos;,&apos;less&apos;],function()&#123;</div><div class="line"></div><div class="line">	// 开启了一个静态资源服务器</div><div class="line">	browserSync.init(&#123;</div><div class="line">        server: &#123;</div><div class="line">            baseDir: &quot;./&quot;</div><div class="line">        &#125;</div><div class="line">    &#125;);</div><div class="line">	// 监听文件变化 文件发生变化之后执行后面的任务</div><div class="line">	gulp.watch([&apos;src/*.html&apos;,&apos;src/css/*.css&apos;],[&apos;htmlmin&apos;,&apos;cssmin&apos;]);</div><div class="line"></div><div class="line">&#125;)</div><div class="line"></div><div class="line">// css压缩</div><div class="line">gulp.task(&apos;cssmin&apos;,function()&#123;</div><div class="line"></div><div class="line">	// 获取要处理的文件</div><div class="line">	gulp.src(&apos;src/css/*.css&apos;)</div><div class="line">		// 压缩操作</div><div class="line">		.pipe(cleanCSS(&#123;compatibility: &apos;ie8&apos;&#125;))</div><div class="line">		.pipe( gulp.dest(&apos;dist/css&apos;) )</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">&#125;);</div><div class="line"></div><div class="line">// js合并压缩</div><div class="line">gulp.task(&apos;jsmin&apos;,function()&#123;</div><div class="line"></div><div class="line">	gulp.src([&apos;src/js/*.js&apos;,&apos;src/views/**/*.js&apos;])</div><div class="line">		// 文件合并 参数是文件合并之后的名字</div><div class="line">		.pipe( concat(&apos;all.min.js&apos;) )</div><div class="line">		// js代码压缩</div><div class="line">		.pipe( uglify() )</div><div class="line">		// 输出处理过后的文件</div><div class="line">		.pipe( gulp.dest(&apos;dist/js&apos;) )</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">&#125;)</div><div class="line"></div><div class="line">// 图片压缩</div><div class="line">gulp.task(&apos;imagemin&apos;,function()&#123;</div><div class="line"></div><div class="line">	gulp.src(&apos;src/images/*&apos;)</div><div class="line">		.pipe( imagemin() )</div><div class="line">		.pipe(gulp.dest(&apos;dist/images&apos;))</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">&#125;)</div><div class="line"></div><div class="line">// html压缩</div><div class="line">gulp.task(&apos;htmlmin&apos;,function()&#123;</div><div class="line"></div><div class="line">	gulp.src(&apos;src/*.html&apos;)</div><div class="line">		.pipe(htmlmin(&#123;collapseWhitespace: true&#125;))</div><div class="line">		.pipe( gulp.dest(&apos;dist&apos;) )</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">	gulp.src(&apos;src/views/**/*.html&apos;)</div><div class="line">		.pipe(htmlmin(&#123;collapseWhitespace: true&#125;))</div><div class="line">		.pipe( gulp.dest(&apos;dist/views&apos;) )</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">&#125;)</div><div class="line"></div><div class="line"></div><div class="line">// less转换成CSS任务</div><div class="line">gulp.task(&apos;less&apos;,function()&#123;</div><div class="line"></div><div class="line">	// 取到要处理的less文件</div><div class="line">	gulp.src(&apos;src/less/*.less&apos;)</div><div class="line">		// 将less转换为CSS</div><div class="line">		.pipe( less() )</div><div class="line">		// 压缩CSS</div><div class="line">		.pipe(cleanCSS(&#123;compatibility: &apos;ie8&apos;&#125;))</div><div class="line">		// 将处理的结果输出</div><div class="line">		.pipe( gulp.dest(&apos;dist/less&apos;) )</div><div class="line">		.pipe(reload(&#123;stream: true&#125;))</div><div class="line"></div><div class="line">&#125;)</div></pre></td></tr></table></figure></p>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr />

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2018 John Doe<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>